import { defineStore } from 'pinia'
import type { Brand } from "../model/brand.ts"
import axios from "../utils/request.ts"

export const useSalesRepsStore = defineStore('sales_reps', {
    state: (): { sales_reps: string[] } => ({
        sales_reps: []
    }),
    persist: true,
    actions: {
        async fetchSalesReps() {
            const response = await axios.get<Map<String, String>[]>('/users/list/sales_reps')
            const salesRepsList = response.data
                .filter(item => !!item['sales_rep']) // 筛选出有效项
                .map(item => item['sales_rep']);   // 提取 sales_rep 字符串

            // 修正2：使用 Set 去重，然后用 Array.from() 转换回数组
            this.sales_reps = Array.from(new Set(salesRepsList));
        },
    }
})